﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Enterprise.Model.ZJRB;
using Enterprise.Data.ZJRB;
using Enterprise.Infrastructure;
using System.Data;
namespace Enterprise.Service.ZJRB
{
    public class ZJRBService
    {
        private readonly Enterprise.Data.ZJRB.ZJRBData dal=new  ZJRBData();
        public ZJRBService()
		{}
		#region  BasicMethod
		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(string ZJRQ,string JH)
		{
			return dal.Exists(ZJRQ,JH);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(Enterprise.Model.ZJRB.ZJRBEntity model)
		{
			return dal.Add(model);
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Enterprise.Model.ZJRB.ZJRBEntity model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(string ZJRQ,string JH)
		{
			
			return dal.Delete(ZJRQ,JH);
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Enterprise.Model.ZJRB.ZJRBEntity GetModel(string ZJRQ,string JH)
		{
			
			return dal.GetModel(ZJRQ,JH);
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<Enterprise.Model.ZJRB.ZJRBEntity> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<Enterprise.Model.ZJRB.ZJRBEntity> DataTableToList(DataTable dt)
		{
			List<Enterprise.Model.ZJRB.ZJRBEntity> modelList = new List<Enterprise.Model.ZJRB.ZJRBEntity>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				Enterprise.Model.ZJRB.ZJRBEntity model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = dal.DataRowToModel(dt.Rows[n]);
					if (model != null)
					{
						modelList.Add(model);
				}
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			return dal.GetRecordCount(strWhere);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			return dal.GetListByPage( strWhere,  orderby,  startIndex,  endIndex);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		//public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		//{
			//return dal.GetList(PageSize,PageIndex,strWhere);
		//}

		#endregion  BasicMethod
		#region  ExtensionMethod
        /// <summary>
        /// 首页钻井进尺数据调用
        /// </summary>
        /// <returns></returns>
        public static string ZJRB_JinchiForIndex()
        {
            //获取最近10天的钻井进尺
            string sql = @"select rownum,a.* from(select t.zjrq,sum(t.zjjc) as zjjc from zjrb t group by t.zjrq order by t.zjrq desc ) a where rownum <=30 order by zjrq asc";
            Enterprise.Data.Common.Data dal = new Data.Common.Data();
            DataSet ds = dal.GetDataSet(sql);
            StringBuilder sb = new StringBuilder();
            sb.Append("<table id='gv'>");
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                sb.Append("<tr>");
                foreach (DataColumn dc in ds.Tables[0].Columns)
                {
                    sb.Append("<td>"+dr[dc]+"</td>");
                }
                sb.Append("</tr>");

            }
            sb.Append("</table>");
            return sb.ToString();
        }
		#endregion  ExtensionMethod

        /// <summary>
        /// 获取所有的日期
        /// </summary>
        /// <returns></returns>
        public DataSet getRiQi()
        {
            string sql = "select distinct(zjrq) as zjrq from zjrb order by zjrq desc";
            Enterprise.Data.Common.Data data = new Data.Common.Data();
            return data.GetDataSet(sql);
        }
    }
}
